<?php defined('SYSPATH') or die('No direct script access.');

class Controller_App extends Controller_Template {

    public $app_config = null;
    public $template = 'template';
    public $language = null;

    public function before() {
        parent::before();

        if ($this->app_config == null)
            $this->app_config = Kohana::$config->load('app');
        
        $this->template->title = $this->app_config['title'];
        $this->template->description = $this->app_config['description'];
        $this->template->keywords = $this->app_config['keywords'];
        
        $this->language = self::getLang();

        $this->template->languages = $this->app_config['languages'];
        $this->template->language = $this->language;

        $language = $this->app_config['languages'][$this->language];

        setlocale(LC_ALL, $language . '.utf-8');
        I18n::lang($language);
    }
    
    public function getLang() {
        if ($this->app_config == null)
            $this->app_config = Kohana::$config->load('app');
        
        return Request::initial()->param('language', $this->app_config['default_language']);
    }
    
    public static function getLanguage() {
        $app_config = Kohana::$config->load('app');
        return Request::initial()->param('language', $app_config['default_language']);
    }

}